package com.unitd.frame.springweb.plugins.velocity;

/**
 * @desc 获取 velocity 的运行时环境
 * @filename RunEnvironment.java
 * @copyright www.unitd.com
 * @author Hudan
 * @version 1.0
 * @date 2017/4/1
 */
public class RunEnvironment {
	private static final String ONLINE = "online";
	private static final String DEV = "dev";
	private static final String TEST = "test";
	private String configEnv = "spring_runmode";
	private static String RUN_MODE = null;

	public RunEnvironment() {
	}

	/**
	 * @desc 获取应用的运行环境
	 * @return
	 */
	public String getRunMode() {
		if(RUN_MODE == null) {
			String mode = System.getenv(this.getConfigEnv());
			if(mode == null || "".equals(mode)) {
				mode = System.getProperty(this.getConfigEnv());
			}

			if(mode != null) {
				if("online".equals(mode)) {
					mode = "online";
				} else if("dev".equals(mode)) {
					mode = "dev";
				} else if("test".equals(mode)) {
					mode = "test";
				}
			} else {
				mode = "dev";
			}

			System.err.println("-Dspring_runmode=" + mode);
			RUN_MODE = mode;
		}

		return RUN_MODE;
	}

	public String getConfigEnv() {
		return this.configEnv;
	}

	public void setConfigEnv(String configEnv) {
		this.configEnv = configEnv;
	}
}